import { tdtConfig } from "./config/tdtConfig";

/**
 * @description:创建底图
 * @param {String} type(底图的名称)
 * @param {Boolean} isBase(是否是底图)
 * @return {Ol.Layer}
 * @Author: yx
 */
function createBaseLayer(type) {
  switch (type) {
    case "tdtImg":
      return new this.TileLayer({
        source: new this.XYZ({
          url: `${tdtConfig.urls.tdtImg}&tk=${tdtConfig.tdtToken}`,
          wrapX: true,
        }),
        isBase: true,
        visible: true,
      });
    case "tdtImgTxt":
      return new this.TileLayer({
        source: new this.XYZ({
          url: `${tdtConfig.urls.tdtImgTxt}&tk=${tdtConfig.tdtToken}`,
          wrapX: true,
        }),
        isBase: true,
        visible: true,
      });
    case "tdtVec":
      return new this.TileLayer({
        source: new this.XYZ({
          url: `${tdtConfig.urls.tdtVec}&tk=${tdtConfig.tdtToken}`,
          wrapX: true,
        }),
        isBase: true,
        visible: true,
      });
    case "tdtVecTxt":
      return new this.TileLayer({
        source: new this.XYZ({
          url: `${tdtConfig.urls.tdtVecTxt}&tk=${tdtConfig.tdtToken}`,
          wrapX: true,
        }),
        isBase: true,
        visible: true,
      });
    case "zjGeoJson":
      let features = [];
      const zjGeoJson = require("@/assets/geojsons/zj.json");
      zjGeoJson.features.map((f) => {
        if (f.geometry.type == "MultiPolygon") {
          let feature = new this.Feature({
            name: f.properties.The_city,
            geometry: new this.MultiPolygon(f.geometry.coordinates),
          });
          feature.setStyle(
            new this.Style({
              fill: new this.Fill({
                color: "#22f3ec40", //填充颜色
              }),
              stroke: new this.Stroke({
                width: 1, //边界宽度
                color: "#fffb00", //边界颜色
              }),
            }),
          );
          features.push(feature);
        } else if (f.geometry.type == "Polygon") {
          let feature = new this.Feature({
            name: f.properties.The_city,
            geometry: new this.Polygon(f.geometry.coordinates),
          });
          feature.setStyle(
            new this.Style({
              fill: new this.Fill({
                color: "#6a92a660", //填充颜色
              }),
              stroke: new this.Stroke({
                width: 1, //边界宽度
                color: "#369285", //边界颜色
              }),
            }),
          );
          features.push(feature);
        }
      });
      // vec图层存放图形数组
      return new this.VectorLayer({
        name: "zjGeoJson",
        isBase: true,
        source: new this.VectorSource({
          features: features,
        }),
      });

    default:
      return new this.TileLayer({
        source: new this.XYZ({
          url: `${tdtConfig.urls.tdtImg}&tk=${tdtConfig.tdtToken}`,
          wrapX: true,
        }),
        isBase: true,
        visible: true,
      });
  }
}

export default createBaseLayer;
